import { ApiProperty } from '@nestjs/swagger';
import { Transform } from 'class-transformer';
import { IsBoolean, IsNumber, IsOptional, IsString } from 'class-validator';

export class UserQueryDto {
  @ApiProperty({
    description: '用户名',
    required: false,
  })
  @IsOptional()
  @IsString()
  username?: string;

  @ApiProperty({
    description: '昵称',
    required: false,
  })
  @IsOptional()
  @IsString()
  nickname?: string;

  @ApiProperty({ description: '状态', required: false, enum: [0, 1] })
  @Transform(({ value }) => {
    // 将数字 1 转为 true，数字 0 转为 false
    if (value === 1 || value === '1') return true;
    if (value === 0 || value === '0') return false;
    return value; // 保留原始值（如果已经是布尔值）
  })
  @IsBoolean()
  @IsOptional()
  status?: boolean;
  
  @ApiProperty({
    description: '部门ID',
    required: false,
  })
  @IsOptional()
  dept_id?: number;

  // 手机号
  @ApiProperty({
    description: '手机号',
    required: false,
  })
  @IsOptional()
  @IsString()
  mobile?: string;
  
  @ApiProperty({
    description: '页码',
    minimum: 1,
    default: 1,
  })
  pageNum: number = 1;

  @ApiProperty({
    description: '每页数量',
    minimum: 1,
    maximum: 100,
    default: 10,
  })
  pageSize: number = 10;
}
